package ch.zbw.sysventory.agent;

import org.apache.log4j.Logger;

import ch.zbw.sysventory.agent.scanner.ComputerScanManager;
import ch.zbw.sysventory.agent.socketserver.AgentTCPServer;
import ch.zbw.sysventory.agent.utils.AgentPropertiesUtil;
import ch.zbw.sysventory.agent.utils.OSHelper;

public class SysVentoryAgent {

	private Logger logger = Logger.getRootLogger();
	private AgentPropertiesUtil propertiesUtil;

	public void start() {
		if (OSHelper.isWindows()) {
			if (this.loadProperties()) {
				AgentTCPServer tcpServer = new AgentTCPServer(propertiesUtil);
				tcpServer.start();

				ComputerScanManager scanManager = new ComputerScanManager();
				scanManager.start();
			}
		} else {
			logger.info("This sysVentory Agent is only supported on Windows!");
		}
	}

	private boolean loadProperties() {
		try {
			this.propertiesUtil = AgentPropertiesUtil.getInstance();
			this.propertiesUtil.load();
			return true;
		} catch (Exception e) {
			logger.error("Cannot load properties", e);
		}
		return false;
	}

}
